package com.neusoft.neuiotms.dcom.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.auth.common.bean.UserBean;
import com.neusoft.bizcore.web.dto.result.PageResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcom.dto.StopServiceNoticeDTO;
import com.neusoft.neuiotms.dcom.service.StopServiceNoticeService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "停止服务通知管理")
@RestController
@RequestMapping(value = "/api/w/stopServiceNotice")
public class StopServiceNoticeController {
    @Autowired
    private StopServiceNoticeService stopServiceService;

    @ApiOperation("查询所有停止服务通知")
    @GetMapping
    public ResultListDTO<StopServiceNoticeDTO> index() {
        final List<StopServiceNoticeDTO> DTOs = this.stopServiceService.findAll();
        final ResultListDTO<StopServiceNoticeDTO> result = ResultListDTO.success(DTOs);
        return result;
    }

    @ApiOperation("分页查询所有停止服务通知")
    @GetMapping("/p")
    public PageResultDTO<StopServiceNoticeDTO> search(final Pageable pageable, final Searchable searchable) {
        return PageResultDTO.success(this.stopServiceService.search(pageable, searchable));
    }

    @ApiOperation("创建停止服务通知")
    @PostMapping
    public ResultDTO<StopServiceNoticeDTO> create(final UserBean operator,
            @RequestBody final StopServiceNoticeDTO dto) {
        if (operator != null) {
            dto.setUserId(operator.getUserId());
            dto.setUserName(operator.getUsername());
        }
        final StopServiceNoticeDTO result = this.stopServiceService.create(dto);
        return ResultDTO.success(result);
    }

    @ApiOperation(value = "修改停止服务通知")
    @PutMapping("/{id}")
    public ResultDTO<StopServiceNoticeDTO> update(@PathVariable final Long id,
            @RequestBody final StopServiceNoticeDTO dto) {
        final StopServiceNoticeDTO result = this.stopServiceService.update(id, dto);
        return ResultDTO.success(result);
    }

    @ApiOperation("停止服务通知详情")
    @GetMapping("/{id}")
    public ResultDTO<StopServiceNoticeDTO> details(@PathVariable final Long id) {
        final StopServiceNoticeDTO dto = this.stopServiceService.details(id);
        return ResultDTO.success(dto);
    }

    @ApiOperation("删除停止服务通知")
    @DeleteMapping("/{id}")
    public ResultDTO<Void> delete(@PathVariable final Long id) {
        this.stopServiceService.delete(id);
        return ResultDTO.success();
    }

    @ApiOperation("重发停止服务通知")
    @GetMapping("/resendMessage/{id}")
    public ResultDTO<Void> resendMessage(@PathVariable final Long id) {
        this.stopServiceService.resendMessage(id);
        return ResultDTO.success();
    }

    @ApiOperation("废弃重发停止服务通知")
    @GetMapping("/discard/{id}")
    public ResultDTO<Void> discard(@PathVariable final Long id) {
        this.stopServiceService.discard(id);
        return ResultDTO.success();
    }

}
